package org.bright.controller;

import org.bright.entity.User;
import org.bright.util.DateUtil;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
@ResponseBody
@RequestMapping("user")
public class UserController {
    //新增
    @PostMapping("saveUser")
    public String saveUser(@RequestBody User user){
        System.out.println(user);
        return "新增用户";
    }
    //修改
    @PostMapping("updateUser")
    public String updateUser(User user){
        System.out.println(user);
        return "修改用户";
    }
    //删除
    @PostMapping("deleteUser")
    public String deleteUser(Integer userId){
        System.out.println(userId);
        return "删除用户";
    }
    //获取用户列表
    @PostMapping("getUserList")
    public List<User> getUserList(String userName,String tel){
        List<User> userList = new ArrayList<>();
        User user = new User();
        user.setUserId(1);
        user.setUserName(userName);
        user.setPassword("123456");
        user.setImageUrl("http://www.baidu.com");
        user.setTel(tel);
        user.setSex("男");
        user.setRegisterDate(DateUtil.stringToDate("2024-09-24","yyyy-MM-dd"));
        userList.add(user);


        User user1 = new User();
        user1.setUserId(1);
        user1.setUserName("李四");
        user1.setPassword("456123");
        user1.setImageUrl("http://www.baidu.com");
        user1.setTel("89498");
        user1.setSex("女");
        user1.setRegisterDate(DateUtil.stringToDate("2028-09-12","yyyy-MM-dd"));
        userList.add(user1);
        return userList;
    }
    //获取用户详情
    @PostMapping("getUserDetail")
    public User getUserDetail(Integer userId){
        User user = new User();
        user.setUserId(1);
        user.setUserName("张三");
        user.setPassword("123456");
        user.setImageUrl("http://www.baidu.com");
        user.setTel("123456789");
        user.setSex("男");
        user.setRegisterDate(DateUtil.stringToDate("2024-09-24","yyyy-MM-dd"));
        return user;
    }
}
